

package com.wwy.monitor.schedulerx2;

import java.util.Date;

import com.alibaba.schedulerx.worker.domain.JobContext;
import com.alibaba.schedulerx.worker.processor.JavaProcessor;
import com.alibaba.schedulerx.worker.processor.ProcessResult;
import com.wwy.monitor.model.enumeration.MonitorTypeEnum;
import com.wwy.monitor.model.tddl.query.MonitorConfigDetailQuery;
import com.wwy.monitor.service.MonitorTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author: æé¨
 * ä¸å¡DBçæ§å®æ¶ä»»å¡
 * @date: 2019/7/16
 */
@Component
public class AmapMonitorDbDataTask {//extends JavaProcessor {
    private static final Logger LOGGER = LoggerFactory.getLogger(AmapMonitorDbDataTask.class);
    @Autowired
    private MonitorTaskService monitorTaskService;

    public void run(String jobArguments) {
        try {
            MonitorConfigDetailQuery query = new MonitorConfigDetailQuery();
            query.setConfigType(MonitorTypeEnum.DATABASE.getValue());
            query.setTaskTime(new Date());
            monitorTaskService.saveTaskByMonitorCongfigDetail(query);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage(), e);
        }
    }

    @Scheduled(fixedDelay = 1000 * 60)
    public ProcessResult process() {
        LOGGER.info("çæ§å¹³å° ä¸å¡DBçæ§å®æ¶ä»»å¡start");
        long start = System.currentTimeMillis();
        run(null);
        long end = System.currentTimeMillis();
        LOGGER.info("çæ§å¹³å° ä¸å¡DBçæ§å®æ¶ä»»å¡end,time={}", end - start);
        return new ProcessResult(true);
    }
}